package android.tusnotas.connector.webcampus;

import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.tusnotas.util.MD5Generator;
import android.tusnotas.util.PropertyLoader;
import android.util.Log;

public class WebCampusFiller {

	private List<NameValuePair> pairs = new ArrayList<NameValuePair>(8);
	private String encoding = "UTF-8";
	
    public WebCampusFiller(){
    	
    	String username = PropertyLoader.USERNAME;
	    String password = PropertyLoader.PASSWORD;
	    
		try {
			this.addParam(new BasicNameValuePair("__LASTFOCUS",""));
			this.addParam(new BasicNameValuePair("__EVENTTARGET",""));
			this.addParam(new BasicNameValuePair("__EVENTARGUMENT",""));
			this.addParam(new BasicNameValuePair("__VIEWSTATE",URLDecoder.decode("%2FwEPDwUKMjA5NjIxOTk3NA9kFgJmD2QWAgIDD2QWBAIDD2QWBAIBD2QWAmYPZBYCAgEPZBYCAgEPZBYCAgEPDxYCHgRUZXh0BQVMb2dpbmRkAgIPDxYCHgdWaXNpYmxlaGQWAgICDw8WAh8BaGRkAgUPZBYEAgMPD2QWAh4MQVVUT0NPTVBMRVRFBQNvZmZkAgcPD2QWAh8CBQNvZmZkZNz6hdt6dYlHFTvxD2WlbAWtj2XB",encoding)));
			this.addParam(new BasicNameValuePair(URLDecoder.decode("ctl00%24ContentPlaceHolderMain%24txtUser",encoding),username));//sbesomi
			this.addParam(new BasicNameValuePair(URLDecoder.decode("ctl00%24ContentPlaceHolderMain%24txtClave1",encoding),password));
			this.addParam(new BasicNameValuePair(URLDecoder.decode("ctl00%24ContentPlaceHolderMain%24btnEntrar",encoding),"Entrar"));		
			this.addParam(new BasicNameValuePair("__EVENTVALIDATION",URLDecoder.decode("%2FwEWBQKF7dnRBgLdsb%2BVAQLHmfH0AgLGh%2FelBQL0zIH0Dkj3eozUPxb4yxyqUY%2FHk0YCtae1",encoding)));
		}

		catch (Exception e) {
			Log.w(MD5Generator.class.getName(),"Encoding: "+ encoding +" not supported");
			e.printStackTrace();
		}
	}

	public void addParam(NameValuePair pair){
		this.getPairs().add(pair);	
	}

	public void setPairs(List<NameValuePair> pairs) {
		this.pairs = pairs;
	}

	public List<NameValuePair> getPairs() {
		return pairs;
	}
}
